Telegram Group & Telegram Channel
🧠 Задача на C#: "Сбалансированное стандартное отклонение"

Условие
Дан список чисел List<double> — это одномерное распределение значений.
Нужно определить: существует ли такой индекс, при котором массив можно разделить на две части, и стандартные отклонения этих частей отличаются не более чем на `epsilon` (например, 0.1).

Пример:


var data = new List<double> { 1.0, 2.0, 3.0, 6.0, 9.0 };
// Разделение после 2 → [1.0, 2.0], [3.0, 6.0, 9.0]
// std_left ≈ 0.707, std_right ≈ 3.0 → слишком большая разница


Формат функции:


public static bool HasBalancedStdSplit(List<double> data, double epsilon = 0.1)


Решение:


using System;
using System.Collections.Generic;
using System.Linq;

public class StatUtils
{
public static bool HasBalancedStdSplit(List<double> data, double epsilon = 0.1)
{
int n = data.Count;
if (n < 4) return false;

for (int i = 2; i <= n - 2; i++)
{
var left = data.Take(i).ToList();
var right = data.Skip(i).ToList();

double stdLeft = StandardDeviation(left);
double stdRight = StandardDeviation(right);

if (Math.Abs(stdLeft - stdRight) <= epsilon)
return true;
}

return false;
}

private static double StandardDeviation(List<double> values)
{
double mean = values.Average();
double sumSquares = values.Sum(v => Math.Pow(v - mean, 2));
return Math.Sqrt(sumSquares / (values.Count - 1));
}
}


Пример использования:


class Program
{
static void Main()
{
var data = new List<double> { 2, 4, 4, 4, 5, 5, 7, 9 };
bool result = StatUtils.HasBalancedStdSplit(data, 0.5);
Console.WriteLine($"Можно ли сбалансировать: {result}");
}
}


Что проверяет задача:

• знание статистики и работы со стандартным отклонением
• навыки эффективной работы с коллекциями
• аккуратность при вычислениях с double
• понимание требований к длине выборки для корректной статистики

Хочешь — могу добавить LINQ-only версию, визуализацию через Plotly.NET или тесты через xUnit.

@csharp_1001_notes



tg-me.com/csharp_1001_notes/683
Create:
Last Update:

🧠 Задача на C#: "Сбалансированное стандартное отклонение"

Условие
Дан список чисел List<double> — это одномерное распределение значений.
Нужно определить: существует ли такой индекс, при котором массив можно разделить на две части, и стандартные отклонения этих частей отличаются не более чем на `epsilon` (например, 0.1).

Пример:


var data = new List<double> { 1.0, 2.0, 3.0, 6.0, 9.0 };
// Разделение после 2 → [1.0, 2.0], [3.0, 6.0, 9.0]
// std_left ≈ 0.707, std_right ≈ 3.0 → слишком большая разница


Формат функции:


public static bool HasBalancedStdSplit(List<double> data, double epsilon = 0.1)


Решение:


using System;
using System.Collections.Generic;
using System.Linq;

public class StatUtils
{
public static bool HasBalancedStdSplit(List<double> data, double epsilon = 0.1)
{
int n = data.Count;
if (n < 4) return false;

for (int i = 2; i <= n - 2; i++)
{
var left = data.Take(i).ToList();
var right = data.Skip(i).ToList();

double stdLeft = StandardDeviation(left);
double stdRight = StandardDeviation(right);

if (Math.Abs(stdLeft - stdRight) <= epsilon)
return true;
}

return false;
}

private static double StandardDeviation(List<double> values)
{
double mean = values.Average();
double sumSquares = values.Sum(v => Math.Pow(v - mean, 2));
return Math.Sqrt(sumSquares / (values.Count - 1));
}
}


Пример использования:


class Program
{
static void Main()
{
var data = new List<double> { 2, 4, 4, 4, 5, 5, 7, 9 };
bool result = StatUtils.HasBalancedStdSplit(data, 0.5);
Console.WriteLine($"Можно ли сбалансировать: {result}");
}
}


Что проверяет задача:

• знание статистики и работы со стандартным отклонением
• навыки эффективной работы с коллекциями
• аккуратность при вычислениях с double
• понимание требований к длине выборки для корректной статистики

Хочешь — могу добавить LINQ-only версию, визуализацию через Plotly.NET или тесты через xUnit.

@csharp_1001_notes

BY C# 1001 notes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/csharp_1001_notes/683

View MORE
Open in Telegram


C 1001 notes Telegram | DID YOU KNOW?

Date: |

The STAR Market, as is implied by the name, is heavily geared toward smaller innovative tech companies, in particular those engaged in strategically important fields, such as biopharmaceuticals, 5G technology, semiconductors, and new energy. The STAR Market currently has 340 listed securities. The STAR Market is seen as important for China’s high-tech and emerging industries, providing a space for smaller companies to raise capital in China. This is especially significant for technology companies that may be viewed with suspicion on overseas stock exchanges.

Export WhatsApp stickers to Telegram on Android

From the Files app, scroll down to Internal storage, and tap on WhatsApp. Once you’re there, go to Media and then WhatsApp Stickers. Don’t be surprised if you find a large number of files in that folder—it holds your personal collection of stickers and every one you’ve ever received. Even the bad ones.Tap the three dots in the top right corner of your screen to Select all. If you want to trim the fat and grab only the best of the best, this is the perfect time to do so: choose the ones you want to export by long-pressing one file to activate selection mode, and then tapping on the rest. Once you’re done, hit the Share button (that “less than”-like symbol at the top of your screen). If you have a big collection—more than 500 stickers, for example—it’s possible that nothing will happen when you tap the Share button. Be patient—your phone’s just struggling with a heavy load.On the menu that pops from the bottom of the screen, choose Telegram, and then select the chat named Saved messages. This is a chat only you can see, and it will serve as your sticker bank. Unlike WhatsApp, Telegram doesn’t store your favorite stickers in a quick-access reservoir right beside the typing field, but you’ll be able to snatch them out of your Saved messages chat and forward them to any of your Telegram contacts. This also means you won’t have a quick way to save incoming stickers like you did on WhatsApp, so you’ll have to forward them from one chat to the other.

C 1001 notes from ms


Telegram C# 1001 notes
FROM USA